/**
 * Abstraction of a page of memory. This class holds all teh actual data. When made
 * it can be set to either be cache or main memory. It also hold the access time
 * for which ever type of memory it is.
 */
package memsim;

public class Memory {

    private Object [][] data; /************need to chage this from object!!!!!!!!!***********/
    private int mem_speed = 0;
    private boolean cache = false;

    /**
     * The constructor which takes in data to be set and flag to specify what type
     * of memory it is.
     *
     * @param d     the data to be held by the memory
     * @param c     flag to set whether the memory is main memory or cache
     */
    public Memory(Object [][] d, boolean c){
        cache = c;
        if(cache){
            mem_speed = 1;
        }else{
            mem_speed = 100;
        }

        data = d;
    }

    /**
     * The method to retrieve the data from the page of memory
     * @return  the data held within the page
     */
    public Object[][] getData(){
        return data;
    }

    /**
     * The method to set the data of a page.
     * 
     * @param d     the data that is going to be placed into the page
     */
    public void setData(Object [][] d){
        data = d;
    }

    /**
     * The method to retrieve data in a specified locaiton.
     *
     * @param addr  the slot in the page where the desired value lies
     * @return      the value in the selected slot
     */
    public Object getValue(int addr){
        return data[addr][1];
    }

    /**
     * The method to return how many cycles it takes for this page of memory.
     *
     * @return  the number of cycles access to this page takes
     */
    public int getSpeed(){
        return mem_speed;
    }

    /**
     * The method to check if the page is a page of cache
     *
     * @return  true if page is cache, else false
     */
    public boolean isCache(){
        return cache;
    }

    /**
     * The method to set a value into a specified slot in this page
     *
     * @param addr  the slot when the data is to be inserted
     * @param d     the data to be inserted
     */
    public void setValue(int addr, Object d){
        data[addr][1] = d;
    }

    /**
     * The method to change the value of an address in a specified slot
     *
     * @param location  the location that needs to be changed
     * @param value     the value to be changed
     */
    public void setAddr(int location, Object value){
        data[location][0] = value;
    }

}
